/*********************************************************
	> File Name: chain_tab.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: 六  8/ 9 11:51:27 2014
 ************************************************************************/
// 链表

#include<stdio.h>
#include <stdlib.h>
#include <string.h>

struct film{
    char name[45];
    int rate;
    struct film *next;
};

int main(void)
{
    struct film *head=NULL;
    struct film *prev, *current;
    char input[45];

    puts("Enter first moive title:  ");
    while(gets(input)!=NULL && input[0]!='\0')
    {
        current=(struct film *)malloc(sizeof(struct film));
        if(head==NULL)
            head=current;
        else
            prev->next=current;
        current->next=NULL;
        strcpy(current->name,input);
        puts("Enter your rate <0-10>: ");
        scanf("%d",&current->rate);
        while(getchar()!='\n')
            continue;
        puts("Enter next movie title (Empty to quit):\n");
        prev=current;
    }
    if(head==NULL)
        printf("NO data input\n");
    else
        printf("the contents are :\n");
    current=head;
    while(current!=NULL)
    {
        printf("Moive: %s\tRate: %d\n",current->name,current->rate);
        current=current->next;
    }
    current=head;
    while(current!=NULL)
    {
        free(current);
        current=current->next;
    }
    printf("Bye\n");

    return 0;
}
